package com.llkj.qingnianguoxue.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.MyCourseBean;
import com.llkj.qingnianguoxue.bean.PreviousActionBean;
import com.llkj.qingnianguoxue.util.DateUtils;
import com.llkj.qingnianguoxue.util.DisplayUtil;
import com.llkj.qingnianguoxue.util.ImageLoadingUtil;

import java.util.List;

/**
 * 我的课程
 */
public class MyCourseAdapter extends BaseQuickAdapter<MyCourseBean, BaseViewHolder> {

    private int mTabType;//0学生预约，1学生完成，2老师将开课，3老师未预约，4老师已预约

    public MyCourseAdapter(int layoutResId, List<MyCourseBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder,MyCourseBean item) {
        ImageView ivPic = baseViewHolder.getView(R.id.iv_action_pic);
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) ivPic.getLayoutParams();
        params.width = DisplayUtil.getDensityWdith(mContext);
        params.height = params.width * 240 / 640;

        ImageLoadingUtil.loadingUrlCenterCrop(ivPic, item.getImg());
        baseViewHolder.setText(R.id.tv_title, item.getName());

        TextView btnState = baseViewHolder.getView(R.id.btn_course_state);
        baseViewHolder.addOnClickListener(R.id.btn_course_state);
        switch (mTabType){
            case 0://学生预约
//                long startTime = 0,endTime=0;
//                try {
//                    startTime = DateUtils.dateFormat(item.getStart_time()).getTime();
//                    endTime = DateUtils.dateFormat(item.getEnd_time()).getTime();
//                }catch (Exception e){}

//                long currentTime = System.currentTimeMillis();
                if("3".equals(item.getState())){
                    if("1".equals(item.getIs_comment())){
                        btnState.setVisibility(View.GONE);
                    }else{
                        btnState.setText("去评价");
                        btnState.setVisibility(View.VISIBLE);
                    }
                }else{
                    btnState.setText("课程未开始");
                    btnState.setVisibility(View.VISIBLE);
                }
//                if(currentTime<startTime){
//                    btnState.setText("课程未开始");
//                    btnState.setVisibility(View.VISIBLE);
//                }else if(currentTime>=startTime && currentTime<=endTime){
//                    btnState.setText("去听课");
//                    btnState.setVisibility(View.VISIBLE);
//                }else{
//                    btnState.setVisibility(View.GONE);
//                }
                break;
            case 1://学生完成
                baseViewHolder.getView(R.id.llButton).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.tv_scan_again).setVisibility(View.GONE);
                baseViewHolder.addOnClickListener(R.id.tv_scan_again);//回看
                baseViewHolder.addOnClickListener(R.id.tv_start_praise);//去评价
                break;
            case 2://老师将开课
                btnState.setVisibility(View.VISIBLE);
                btnState.setText("去开课");
                break;
            case 3://老师未预约
                btnState.setVisibility(View.VISIBLE);
                btnState.setText("已完结");
                break;
            case 4://老师已预约
                btnState.setVisibility(View.VISIBLE);
                btnState.setText("未预约");
                break;
        }
    }

    public void setTabType(int type){
        mTabType = type;
    }
}
